//
//  HCADetailView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/2/6.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCADetailView.h"

#import "PWContentView.h"


#import "CWStarRateView.h"

@interface HCADetailView () {
    UIImageView *imageView;
    UILabel *timeLabel;
    
    UILabel *titleLabel;
    UILabel *addressLabel;
    CWStarRateView *starView;
    PWContentView *pw;
    UIButton *callBtn;
}

@end

@implementation HCADetailView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubView:frame];
    }
    return self;
}

-(void)initializeSubView:(CGRect)frame {
    
    self.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, YBKAdaptiveH(225))];
    imageView.image = [UIImage imageNamed:@"happy_appd_top"];
    [self addSubview:imageView];
    
    UIView *vb = [[UIView alloc] initWithFrame:imageView.frame];
    vb.backgroundColor = [UIColor blackColor];
    vb.alpha = 0.3;
    [self addSubview:vb];
    
    UIView *contentMiddle = [[[NSBundle mainBundle] loadNibNamed:@"contentmiddleview" owner:self options:nil]firstObject];
    contentMiddle.frame = CGRectMake(0, imageView.frame.size.height, frame.size.width, YBKAdaptiveH(83));
    
    titleLabel = (UILabel *)[contentMiddle viewWithTag:10111];
    addressLabel = (UILabel *)[contentMiddle viewWithTag:103];
    starView = (CWStarRateView *)[contentMiddle viewWithTag:101010];
    callBtn = (UIButton *)[contentMiddle viewWithTag:104];
    [callBtn addTarget:self action:@selector(callBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:contentMiddle];
    
    UIView *line1 = (UIView *)[contentMiddle viewWithTag:101];
    UIView *line2 = (UIView *)[contentMiddle viewWithTag:102];
    
    line1.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    line2.backgroundColor = line1.backgroundColor;
    
    UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(0, contentMiddle.frame.origin.y+contentMiddle.frame.size.height+5, frame.size.width, YBKAdaptiveH(60))];
    middleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:middleView];
    
    UIView *line3 = [[UIView alloc] initWithFrame:CGRectMake(0, YBKAdaptiveH(30), frame.size.width, .5f)];
    line3.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [middleView addSubview:line3];
    
    //上边，下边的view
    UIView *tView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, line3.frame.origin.y)];
    [middleView addSubview:tView];
    
    
    UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, line3.frame.origin.y+line3.frame.size.height, frame.size.width, middleView.frame.size.height - line3.frame.origin.y-line3.frame.size.height)];
    [middleView addSubview:bView];
    
    timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, (bView.frame.size.height - 20)/2.0, frame.size.width-25, 20)];
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.text = @"营业时间：10：00-20：00";
    timeLabel.font = [UIFont systemFontOfSize:12];
    [bView addSubview:timeLabel];
    
    UIImageView *imagewifi = [[UIImageView alloc] initWithFrame:CGRectMake(25, (tView.frame.size.height - 14)/2.0, 14, 14)];
    imagewifi.image = [UIImage imageNamed:@"happy_appd_wifi"];
    [tView addSubview:imagewifi];
    
    UILabel *labelWIFI = [[UILabel alloc]initWithFrame:CGRectMake(imagewifi.frame.origin.x+imagewifi.frame.size.width+4, (tView.frame.size.height - 20)/2.0, 120, 20)];
    labelWIFI.textColor = [UIColor lightGrayColor];
    labelWIFI.text = @"WIFI";
    labelWIFI.font = [UIFont systemFontOfSize:14];
    [tView addSubview:labelWIFI];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, middleView.frame.origin.y+middleView.frame.size.height+5, frame.size.width, YBKAdaptiveH(158))];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self addSubview:bottomView];
    
    UILabel *labelProject = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 200, 20)];
    labelProject.textColor = [UIColor darkGrayColor];
    labelProject.font = [UIFont systemFontOfSize:15];
    labelProject.text = @"项目介绍";
    [bottomView addSubview:labelProject];
    
    NSArray *arr = @[@"室内拓展",@"游泳",@"超级海洋池",@"按摩",@"积木屋",@"开心哈乐城堡"];
    
    pw = [[PWContentView alloc] initWithFrame:CGRectMake(YBKAdaptiveW(35), labelProject.frame.origin.y+labelProject.frame.size.height, frame.size.width - YBKAdaptiveW(52), bottomView.frame.size.height - labelProject.frame.origin.y-labelProject.frame.size.height) dataArr:arr];
    pw.backgroundColor = [UIColor whiteColor];
    [bottomView addSubview:pw];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((self.frame.size.width - YBKAdaptiveW(355))/2.0, self.frame.size.height - YBKAdaptiveW(50)-YBKAdaptiveW(42), YBKAdaptiveW(355), YBKAdaptiveW(42))];
    [btn setBackgroundImage:[UIImage imageNamed:@"happy_appd_sure"] forState:UIControlStateNormal];
//    [btn setBackgroundColor:[UIColor blackColor]];
    [btn addTarget:self action:@selector(smsBtnAction111:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
//    UIButton *all = [[UIButton alloc] initWithFrame:CGRectMake((self.frame.size.width), self.frame.size.height - YBKAdaptiveW(50)-10, YBKAdaptiveW(298), YBKAdaptiveW(50))];
//    [btn addTarget:self action:@selector(smsBtnAction111:) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:all];
    
}

-(void)setModel:(HCAppointmentDetailModel *)model {
    _model = model;
    
    [imageView sd_setImageWithURL:[NSURL URLWithString:_model.logo] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        imageView.image = image;
    }];
    
    timeLabel.text = [NSString stringWithFormat:@"营业时间：%@",_model.time];
    
    
    if ([PublicFunction isNull:_model.name]) {
        titleLabel.text = @"未命名";
    }else {
        titleLabel.text = [NSString stringWithFormat:@"%@",_model.name];
    }
    NSString *ti = [NSString stringWithFormat:@"%@",model.about];
    if (![PublicFunction isNull:ti]) {
        NSArray *arr = [ti componentsSeparatedByString:@","];
        NSLog(@"预约项目:%@",arr);
        pw.array = arr;
    }

    addressLabel.text = [NSString stringWithFormat:@"地址：%@",_model.location];
    
    starView.scorePercent = [_model.star floatValue]/5.0;
    
    
    
}

-(void)callBtnAction:(UIButton *)btn {
    NSLog(@"打电话");
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_model.phone]]];
    
}


-(void)smsBtnAction111:(UIButton *)btn {
    NSLog(@"预约门店");
    if ([self.delegate respondsToSelector:@selector(hcAppointmentClicked)]&&self.delegate) {
        [self.delegate hcAppointmentClicked];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
